package com.anXin.mall.controller;

import com.anXin.mall.service.GoodsService;
import com.anXin.model.common.dtos.ResponseResult;
import com.anXin.model.mall.pojos.Goods;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @GetMapping("/getPage/{page}&{pageSize}")
    public ResponseResult<Page<Goods>> getPage(@PathVariable int page, @PathVariable int pageSize){
        return goodsService.getGoodsPage(page,pageSize);
    }

    @GetMapping("/getGoods/{id}")
    public ResponseResult<Goods> getGoods(@PathVariable Long id){
        return goodsService.getGoods(id);
    }

    @PutMapping("/update")
    public ResponseResult<String> updateGoods(@RequestBody Goods goods){
        log.info("{}",goods);
        return goodsService.updataGoods(goods);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult<String> deleteGoods(@PathVariable Long id){
        return goodsService.deleteGoods(id);
    }
}
